package com.example.buyticketlishi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.buyticketlishi.R;
import com.example.buyticketlishi.bean.RzfindTimeControlListResultBean;

import java.util.List;

public class SelectTimeAdapter extends BaseAdapter {

    private Context context;
    private List<RzfindTimeControlListResultBean.DataBean.TimeControlListBean> timeSelectList;
    private TextView tvTime;
    private TextView tvTicketNumber;
    public GridViewItemListener gridViewItemListener;
    public LinearLayout llSelect;

    public SelectTimeAdapter(Context context, List<RzfindTimeControlListResultBean.DataBean.TimeControlListBean> timeSelectList) {
        this.context = context;
        this.timeSelectList = timeSelectList;


    }

    @Override
    public int getCount() {
        return timeSelectList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View menuItem = LayoutInflater.from(context).inflate(R.layout.wigit_time_select_item, null);

        tvTime = menuItem.findViewById(R.id.tv_time_select_show);
        tvTicketNumber = menuItem.findViewById(R.id.tv_time_select_have_ticket_number);
        llSelect = menuItem.findViewById(R.id.ll_time_select);

        tvTime.setText(timeSelectList.get(position).getControlStartTime() + "-" + timeSelectList.get(position).getControlEndTime());
        tvTicketNumber.setText("剩余：" + timeSelectList.get(position).getResidueSum());

        llSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gridViewItemListener.gvItem(position);
            }
        });

        return menuItem;
    }

    public interface GridViewItemListener{
        void gvItem(int pos);
    }

    public void SetGridViewItemListener(GridViewItemListener gridViewItemListener){
        this.gridViewItemListener = gridViewItemListener;
    }
}
